package com.imessage.service.impl;

import com.bean.BaseConfig;
import com.imessage.service.BaseService;
import com.imessage.service.ConfigService;
import com.imessage.type.BaseConfigCode;
import com.imessage.type.BaseState;
import io.ebean.Expr;
import io.ebean.Expression;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service
public class ConfigServiceImpl implements ConfigService {

    @Autowired
    private BaseService baseService;

    public BaseConfig findObject(BaseConfigCode baseConfigCode){
        List<Expression> expressionList=new ArrayList<Expression>();
        expressionList.add(Expr.eq("code", baseConfigCode.getCode()));
        expressionList.add(Expr.eq("state", BaseState.normal.getCode()));
        return baseService.findObject(BaseConfig.class, expressionList);
    }

    public List<BaseConfig> findList(List<String> codeList){
        List<Expression> expressionList=new ArrayList<Expression>();
        expressionList.add(Expr.in("code", codeList));
        expressionList.add(Expr.eq("state", BaseState.normal.getCode()));
        return baseService.findList(BaseConfig.class, expressionList);
    }
}
